<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
    <base href="<%=basePath%>">
    
    <title>管理员列表展示</title>
     <!-- 给当前页面域添加一段java代码，用来自动获取当前项目名，不写死,然后再通过EL表达式获取 -->
    <%
    	pageContext.setAttribute("PATH",request.getContextPath());
    
     %>
    
	
  	
  <!-- 搭建主页面显示 -->
  <div>
  
  			<!--添加模态框的显示-->
				<div class="modal fade" id="mymodal">
					<div class="modal-dialog"><!--对话框-->
						<div class="modal-content"><!--内容-->
							<div class="modal-header"><!--头部-->
								<div class="close" data-dismiss="modal">&times;</div><!--关闭按钮-->
									添加管理
							</div>
							
							<div class="modal-body" id="form-context"><!--身体-->
								<form class="form-horizontal">
								  <div class="form-group">
								    <label for="inputEmail3" class="col-md-2 control-label">登录名</label>
								    <div class="col-md-6">
								      <input type="text" class="form-control" value="1111" name="username" placeholder="Name" required="required">
								    </div>
								  </div>
								  <div class="form-group">
								    <label for="inputPassword3" class="col-md-2 control-label">密码</label>
								    <div class="col-md-6">
								      <input type="password" class="form-control" name="password" placeholder="Password" required="required">
								    </div>
								  </div>
								 	
								 	<div class="modal-footer"><!--尾部-->
										<button class="btn btn-danger" data-dismiss="modal">Close</button>
										<input type="button" class="btn btn-success save" value="注册">
									</div>
								</form>
							</div>
							
							
						</div>
					</div>
				</div>
				
  			
  	<!-- 标题行 -->
    			<h3><span class="label label-info ">德林文化传媒有限公司</span></h3>
    	
    	<!-- 员工展示列表 -->
     <table class="table table-striped table table-hover" id="admin_table">
       <tr>
	       <th>ID</th>
	       <th>姓名</th>
	       <th>密码</th>
	       <th>操作</th>  
		      
		       <div class="row">
		    		<div class="col-md-4 col-md-offset-6">
		    			 <button class="btn btn-primary" data-toggle="modal" data-target="#mymodal">
		    				<span class="glyphicon glyphicon-plus"></span>
		    				添加管理员
				       	</button>
    				</div>
    			</div>
    		
       </tr>
         <c:forEach items="${admins}" var="list">
            <tr>
           	 	<td>${list.id}</td>
           	 	<td>${list.username}</td>
           	 	<td>${list.password}</td>
           	 	
           	 	<td>
           	 		<div class="row">
			    		<div class="col-md-6 col-md-offset-0">
			    			<button type="button" class="btn btn-warning" onclick="updateadmin(${list.id})">
			    				<span class="glyphicon glyphicon-scissors"></span>
			    					修改
			    				
			    			</button>
			    			<button type="button" class="btn btn-danger" onclick="deleteadmin(${list.id})">
			    				<span class="glyphicon glyphicon-trash"></span>
			    					删除
			    			</button>
	    				</div>
    				</div>
           	 	</td>
           	 </tr>
        </c:forEach> 
        
     </table>
    		
    </div>	
    	
   	<script>
   	
   	
   	
   		<!-- 定一个添加用户的方法-->
		 $(".save").click(function(){
		 	$.ajax({
    			url:"${PATH}/admin/insert.do",//请求控制层的绝对路径
    			type:"POST",
    			data:$("#form-context form").serialize(),//发送给服务器的数据
    			dataType:"json",
    			success:function(map){
    				//1、关闭模态框
    				$("#mymodal").modal("hide");
    				 location.href="${PATH}/admin/AllAdmins.do";
    				 
    			},
    			error:function(){
    			alert(22222);
    			}
    		});
			
		}); 
		
		
		
		<!-- 定一个提醒用户删除的方法，参数就是用户的ID -->
		function deleteadmin(id){
			if(confirm("确定要删除id为"+id+"的管理吗？")){
			
				//如果确定，就访问controller层
				location.href="${PATH}/admin/delete.do/?id="+id;
				var num = '<%=session.getAttribute("num")%>';
				
				 if(num != 0){
					alert("删除"+id+"成功！")
				}else{
					alert("删除"+id+"失败！")
				} 
			}
		}
		
		<!-- 定一个提醒用户修改的方法，参数就是用户的ID -->
		function updateadmin(id){
			if(confirm("确定要修改id为"+id+"的管理吗？")){
			
				//如果确定，就访问controller层
				location.href="${PATH}/admin/updateJsp.do/?id="+id;
			}
		}
		 
	</script>